      function validateForm(form) {
        //Check title
        var title = document.getElementById("title");
        if (trimString(title.value) == '') {
          alert("กรุณากรอกหัวข้อ");
          document.getElementById('error-title').innerHTML = "*กรุณากรอกหัวข้อ";
          title.style.borderStyle = "solid";
          title.style.borderColor = "#FF0000";
          title.style.borderWidth = "1px";
          title.focus();
          return false;
        }else{
          title.style.borderStyle = "solid";
          title.style.borderColor = "#00CC00";
          title.style.borderWidth = "1px";
          document.getElementById('error-title').innerHTML = "<IMG SRC='modules/InnoForum/pnimages/right.gif' WIDTH='10' HEIGHT='10'>";
        }

        //Check category
        var category = document.getElementById("form_category_id_");
        if (category.value == 0) {
          alert("กรุณาเลือกหมวดหมู่");
          document.getElementById('error-category').innerHTML = "*กรุณาเลือกหมวดหมู่";
          category.style.borderStyle = "solid";
          category.style.borderColor = "#FF0000";
          category.style.borderWidth = "1px";
          category.focus();
          return false;
        }else{
          category.style.borderStyle = "solid";
          category.style.borderColor = "#00CC00";
          category.style.borderWidth = "1px";
          document.getElementById('error-category').innerHTML = "<IMG SRC='modules/InnoForum/pnimages/right.gif' WIDTH='10' HEIGHT='10'>";
        }

        //Check subcategory
        var subcategory = document.getElementById("form_subcategory_id_");
        //alert(subcategory);
        if(subcategory == null){
          subcategory = document.getElementById("form[subcat_id]");
        }
        if (subcategory.value == 0) {
          alert("กรุณาเลือกหมวดหมู่ย่อย");
          document.getElementById('error-category').innerHTML = "*กรุณาเลือกหมวดหมู่ย่อย";
          subcategory.style.borderStyle = "solid";
          subcategory.style.borderColor = "#FF0000";
          subcategory.style.borderWidth = "1px";
          subcategory.focus();
          return false;
        }else{
          subcategory.style.borderStyle = "solid";
          subcategory.style.borderColor = "#00CC00";
          subcategory.style.borderWidth = "1px";
          //document.getElementById('error-subcategory').innerHTML = "<IMG SRC='modules/InnoForum/pnimages/right.gif' WIDTH='10' HEIGHT='10'>";
        }

        //Check brand
        var brand = document.getElementById("form_brand_id_");
        if (brand.value == 0) {
          alert("กรุณาเลือกยี่ห้อ");
          document.getElementById('error-category').innerHTML = "*กรุณาเลือกยี่ห้อ";
          brand.style.borderStyle = "solid";
          brand.style.borderColor = "#FF0000";
          brand.style.borderWidth = "1px";
          brand.focus();
          return false;
        }else{
          brand.style.borderStyle = "solid";
          brand.style.borderColor = "#00CC00";
          brand.style.borderWidth = "1px";
          //document.getElementById('error-subcategory').innerHTML = "<IMG SRC='modules/InnoForum/pnimages/right.gif' WIDTH='10' HEIGHT='10'>";
        }

        //Check brand
        var model = document.getElementById("form_model_id_");
        if (model.value == 0) {
          alert("กรุณาเลือกรุ่น");
          document.getElementById('error-category').innerHTML = "*กรุณาเลือกรุ่น";
          model.style.borderStyle = "solid";
          model.style.borderColor = "#FF0000";
          model.style.borderWidth = "1px";
          model.focus();
          return false;
        }else{
          model.style.borderStyle = "solid";
          model.style.borderColor = "#00CC00";
          model.style.borderWidth = "1px";
          //document.getElementById('error-subcategory').innerHTML = "<IMG SRC='modules/InnoForum/pnimages/right.gif' WIDTH='10' HEIGHT='10'>";
        }

        //Check type
        var type = document.getElementById("form_type_id_");
        if (type.value == 0) {
          alert("กรุณาเลือกประเภท");
          document.getElementById('error-type').innerHTML = "*กรุณาเลือกประเภท";
          type.style.borderStyle = "solid";
          type.style.borderColor = "#FF0000";
          type.style.borderWidth = "1px";
          type.focus();
          return false;
        }else{
          type.style.borderStyle = "solid";
          type.style.borderColor = "#00CC00";
          type.style.borderWidth = "1px";
          document.getElementById('error-type').innerHTML = "<IMG SRC='modules/InnoForum/pnimages/right.gif' WIDTH='10' HEIGHT='10'>";
        }

        //Check province
        var province = document.getElementById("form_province");
        if (province.value == 0) {
          alert("กรุณาเลือกจังหวัดของประกาศ");
          document.getElementById('error-province').innerHTML = "*กรุณาเลือกจังหวัดของประกาศ";
          province.style.borderStyle = "solid";
          province.style.borderColor = "#FF0000";
          province.style.borderWidth = "1px";
          province.focus();
          return false;
        }else{
          province.style.borderStyle = "solid";
          province.style.borderColor = "#00CC00";
          province.style.borderWidth = "1px";
          document.getElementById('error-province').innerHTML = "<IMG SRC='modules/InnoForum/pnimages/right.gif' WIDTH='10' HEIGHT='10'>";
        }

        //Check Price
        var price = document.getElementById("form_price");
        if(!check_number(price.value) || trimString(price.value) == '' ){
          alert('กรุณากรอกตัวเลข โดยไม่ต้องใส่ , ขั้นระหว่างตัวเลข');
          document.getElementById('error-price').innerHTML = "*กรุณากรอกตัวเลข";
          price.style.borderStyle = "solid";
          price.style.borderColor = "#FF0000";
          price.style.borderWidth = "1px";
          price.focus();
          return false;
        }else{
          price.style.borderStyle = "solid";
          price.style.borderColor = "#00CC00";
          price.style.borderWidth = "1px";
          document.getElementById('error-price').innerHTML = "<IMG SRC='modules/InnoForum/pnimages/right.gif' WIDTH='10' HEIGHT='10'>";
        }

      }

      function trimString (str) 
      {
        str = this != window? this : str;
        return str.replace(/\s+/g, '').replace(/\s+$/g, '');
      }

      function check_number(ch){
        var len, digit;
        if(ch == " "){
          return false;
          len=0;
        }else{
          len = ch.length;
        }
        for(var i=0 ; i<len ; i++) {
          digit = ch.charAt(i)
          if(digit >="0" && digit <="9"){
          
          }else{
            return false;
          }
        }
        return true;
      }

      function getSubCategory(obj){
        var div_subcate = document.getElementById('subcategory_container');
        var category = document.getElementById('form_category_id_');
        var filter = "&filter=scy_category_id = '" + category.value + "'";
        var name = "&name=form[subcategory_id]";
        var url = "index.php?module=InnoForum&type=ajax&func=selector&ctrl=Sub_Category" + filter + name + genSession() ;
        div_subcate.innerHTML ="Loading...";
        new Ajax.Request(url, {
            method:'get',
            onSuccess: function(transport){
             var result = transport.responseText;
             div_subcate.innerHTML= result;
             }   
          });
      }
      function genSession(){
        return '&r=' + Math.random(999);
      }

      var item_count = 1;
      var max_item = 15;
      function addFileItem(){
        if (item_count < max_item){
          var div = document.getElementById('fileitemcontainer');
          var file = document.createElement('input');
          var br   = document.createElement('br');
          file.setAttribute('name' , 'images[]');
          file.setAttribute('type' , 'file');
          file.setAttribute('size' , '51');
          div.appendChild(file);
          div.appendChild(br);
          item_count++;
        }else{
          var addMore = document.getElementById('addFileMore');
          addMore.innerHTML = "";
        }
        return false;
      }
      function onSubmit(){
        var buttonContainner = document.getElementById('button');
        buttonContainner.align = 'center';
        buttonContainner.innerHTML = 'Uploading please wait...<br /><img src="<!--[modulepath]-->/pnimages/loading.gif" />';
        form.submit();

        return false;
      }

      function onPreviewColor_click(containner_id){
        var containner = document.getElementById(containner_id);
        var fgcolor = document.getElementById('fgcolor').value;
        var bgcolor = document.getElementById('bgcolor').value;
        if (containner != null ){
          if ( fgcolor != '#000000'){
            containner.style.color = fgcolor;
          }
          if ( bgcolor != '#000000'){
            containner.style.backgroundColor  = bgcolor;
          }else{
            containner.style.backgroundColor  = '';
          }
        }
      }